package fatworm.query;

import fatworm.storage.table.*;

public class SelectPlan implements Plan {
	
	private Plan p;
	private Predicate pred;
	
	public SelectPlan(Plan p, Predicate pred) {
		this.p = p;
		this.pred = pred;
	}
	
	public Scan open() {
		Scan s = p.open();
		return new SelectScan(s, pred);
	}
	
	public int blocksAccessed() {
		return p.blocksAccessed();
	}
	
	public int recordsOutput() {
		return p.recordsOutput() / pred.reductionFactor(p);
	}
	
	public int distinctValues(String name) {
		return Math.min(p.distinctValues(name), recordsOutput());
	}
	
	public Schema getSchema() {
		return p.getSchema();
	}
}